/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.digitaldiary.notify;


import java.util.Properties;
import java.util.Timer;
import java.util.TimerTask;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.PasswordAuthentication;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
/**
 *
 * @author Sanjay
 */
public class Mail {
   
    private String username= "digitaldiaryinfo";
    private String password= "dd123456" ;
    private String recipientMail;
    private String subject;
    private String messageBody;

   
    /**
     * @param args the command line arguments
     */
  
    public void sendMail(String recipientMail,  String subject, String messageBody){
           
		Properties props = new Properties();
		props.put("mail.smtp.auth", "true");
		props.put("mail.smtp.starttls.enable", "true");
		props.put("mail.smtp.host", "smtp.gmail.com");
		props.put("mail.smtp.port", "587");
 
		Session session = Session.getInstance(props,
		  new javax.mail.Authenticator() {
                 
			protected PasswordAuthentication getPasswordAuthentication() {
				return new PasswordAuthentication(username, password);
			}
		  });
 
		try {
 
			Message message = new MimeMessage(session);
			message.setFrom(new InternetAddress(username));
			message.setRecipients(Message.RecipientType.TO,
				InternetAddress.parse(recipientMail));
			message.setSubject(subject);
			message.setText(messageBody);
 
			Transport.send(message);
                        System.out.println("Massege sent");
                      
		} catch (MessagingException e) {
                    System.out.println( "Your message could not be sent\n\nPassword or e-mail is incorrect");	
         
                }
                
               }
    }